package com.linewell.encryption.services.impl;


import com.linewell.encryption.pojo.SM2KeyInfo;
import com.linewell.encryption.services.CreateKeyService;
import com.linewell.encryption.utils.ByteUtils;
import com.linewell.encryption.utils.sm2.SM2CreateKeyUtils;
import com.linewell.encryption.utils.sm2.vo.SM2KeyVO;
import com.linewell.encryption.utils.sm4.SM4Utils;

/**
 * 生成秘钥
 * Company: 南威软件股份有限公司
 *
 * @author wucan
 * @date 2019-03-21
 */
public class CreateKeyServiceImpl implements CreateKeyService {

    @Override
    public SM2KeyInfo createSM2Key() throws Exception {
        SM2KeyInfo info = new SM2KeyInfo();
        SM2KeyVO sm2KeyVO = SM2CreateKeyUtils.generateKeyPair();
        info.setPublicKey(sm2KeyVO.getPubHexInSoft());
        info.setPrivateKey(sm2KeyVO.getPriHexInSoft());
        return info;
    }

    @Override
    public String createSM4Key() throws Exception {
        byte[] key = SM4Utils.generateKey();
        return ByteUtils.byteToHex(key);
    }


}
